{template 'web/hairsalon/base_menu'}
<script src="{MODULE_URL}template/resources/js/jquery-ui.min.js"></script>

<div class="top_tab"> 
  <a href="{php echo $this->createWebUrl('member',array('op'=>'display'))}" class="layui-btn {if $operation!='display'}layui-btn-primary{/if}">会员列表</a> 
  <a href="{php echo $this->createWebUrl('member',array('op'=>'display_chargefee'))}" class="layui-btn {if $operation!='display_chargefee'}layui-btn-primary{/if}">会员充值</a> 
  <a href="{php echo $this->createWebUrl('member',array('op'=>'display_gift'))}" class="layui-btn {if $operation!='display_gift'}layui-btn-primary{/if}">积分礼物</a> 
  <a href="{php echo $this->createWebUrl('member',array('op'=>'display_giftrecord'))}" class="layui-btn {if $operation!='display_gift'}layui-btn-primary{/if}">兑换记录</a> 
  
  <div class="secrchinput">
  <form action="" method="post" class="layui-form" onsubmit="renturn false;">
    <button type="submit" id="btn_search" lay-submit="" lay-filter="btn_search"><i class="fa fa-search"></i></button>
    <input type="text" lay-verify="required" name="txtTopupSeachStr" id="txtTopupSeachStr" placeholder="">
  </form>
  </div>
</div>
<style>
.panelbox-head i{ color:#009688;}
.panelbox-head a{ display:inline-block; margin-right:10px}
.help{ font-size:80%; color:#999}
</style>
{if $operation == 'display'}
<div class="panelbox">
<form action="" method="post" class="layui-form" id="listform" enctype="multipart/form-data">
  <div class="panelbox-head"> 
  	<A href="#" onclick="editBox(0)"><i class="fa fa-plus"></i> 新增</A> 
    <A href="#" onclick="batchOperation()"><i class="fa fa-log-in"></i> 导入</A> 
    <A href="#" onclick="excelout()"><i class="fa fa-log-out"></i> 导出</A>
    <A href="#" lay-submit="" lay-filter="btnlost"><i class="fa fa-off"></i> 挂失</A> 
    <span class="help">*选择内容时，请直接点击所在行，请勿点击首列的复选框。名字有红点即表明已绑定微信会员卡</span>
  </div>
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table" lay-skin="line">
        <thead>
          <tr>
            <th style="width:60px"></th>
            <th style="width:120px">卡号</th>
            <th style="width:110px">姓名</th>
            <th style="width:110px">电话</th>
            <th>等级</th>
            <th>积分</th>
            <th>余额</th>
            <th>状态</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody id="memberlist">
          {loop $list $row}
          <tr mid="{$row['id']}" onclick="checkthis(this)">
            <td><input type="checkbox" name="mid[{$row['id']}]" value="{$row['id']}" lay-skin="primary"></td>
            <td>{$row['cardno']}</td>
            <td>{if $row['uid']}<span class="layui-badge-dot"></span>{/if}{$row['realname']}</td>
            <td>{$row['mobile']}</td>
            <td>{php echo $groupAry[$row['gid']]}</td>
            <td>{$row['credit']}</td>
            <td>{$row['cash']}</td>
            <td>{if $row['status']==1}<span class="label label-success">启用</span>{elseif $row['status']==0}<span class="label label-default">未启用</span>{elseif $row['status']==2}<span class="label label-danger">挂失</span>{/if}</td>
            <td>
            	<a href="javascript:editBox({$row['id']})" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a> 
            	<a href="javascript:deleteContent('{php echo $this->createWebUrl('member',array('op'=>'deletemember','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a>
            </td>
          </tr>
          {/loop}
        </tbody>
      </table>
    </div>
  </div>
  <div class="panelbox-foot">
    <div id="pageindex" ></div>
  </div>
  </form>
</div>

<style>
.layui-form-label{ width:80px; padding-left:0; padding-right:0;}
.layui-input-block{margin-left: 100px;}
</style>
<div id="editbox" style="display:none;">
  <form id="editform" class="layui-form" action="" style="padding:15px">
    <input type="hidden" name="id" />
    <div class="row">
      <div class="col-md-6">
        <div class="layui-form-item">
          <label class="layui-form-label">*会员卡号</label>
          <div class="layui-input-block">
            <input type="text" name="cardno" lay-verify="number" autocomplete="off" placeholder="会员卡号" class="layui-input">
          </div>
        </div>
      </div>
      <div class="col-md-6">
        <select name="gid" lay-verify="required" lay-ignore class="form-control">
          <option value="0" selected>会员等级</option>
          {loop mc_groups() $row}
          <option value="{$row['groupid']}">{$row['title']}</option>
          {/loop}
        </select>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">会员姓名</label>
          <div class="layui-input-block">
            <input type="text" name="realname" autocomplete="off" placeholder="会员姓名" class="layui-input">
          </div>
        </div>
      </div>
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">手机号码</label>
          <div class="layui-input-block">
            <input type="text" name="mobile" lay-verify="phone" autocomplete="off" placeholder="手机号码" class="layui-input">
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">会员称谓</label>
          <div class="layui-input-block">
            <input type="radio" name="sex" value="0" title="保密" checked/>
            <input type="radio" name="sex" value="2" title="女士"/>
            <input type="radio" name="sex" value="1" title="先生"/>
          </div>
        </div>
      </div>
      <div class="col-md-6" id="goodstatus">
      	<label class="layui-form-label">会员生日</label>
        <div class="layui-input-block">
          <input class="layui-input" placeholder="会员生日" name="birdday" id="LAY_demorange_s">
        </div>
      </div>
    </div>
    
    <div class="row">
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">微信会员卡</label>
          <div class="layui-input-block">
            <input type="text" name="wxcardno" autocomplete="off" placeholder="微信会员卡卡号" class="layui-input">
          </div>
        </div>
      </div>
      <div class="col-md-6">
      	
      </div>
    </div>
    
    <div class="row">
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">积分</label>
          <div class="layui-input-block">
            <input type="text" name="credit" autocomplete="off" placeholder="积分" class="layui-input">
          </div>
        </div>
      </div>
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">余额</label>
          <div class="layui-input-block">
            <input type="text" name="cash"  autocomplete="off" placeholder="余额" class="layui-input">
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">标签</label>
          <div class="layui-input-block">
            <input type="text" name="label" autocomplete="off" placeholder="标签" class="layui-input">
          </div>
        </div>
      </div>
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">过期时间</label>
          <div class="layui-input-block">
            <input class="layui-input" placeholder="过期时间" name="endtime" id="LAY_demorange_e">
          </div>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">备注</label>
          <div class="layui-input-block">
            <input type="text" name="remark" autocomplete="off" placeholder="50字内" class="layui-input">
          </div>
        </div>
      </div>
      <div class="col-md-6">
      	<div class="layui-form-item">
          <label class="layui-form-label">状态</label>
          <div class="layui-input-block" style="font-size:10px;">
            <input type="radio" name="status" value="0" title="停用"/>
            <input type="radio" name="status" value="1" title="启用" checked/>
            <input type="radio" name="status" value="2" title="挂失"/>
          </div>
        </div>
      </div>
    </div>
    <div class="row">
    	<div class="col-md-12"><Div class="pull-right"> <button class="layui-btn" lay-submit="" lay-filter="btnsubmit">保存</button></Div></Div>
    </div>
  </form>
</div>

<div id="batchOperation" style="display:none;">
  <form id="batchOperationform" class="layui-form" action="" style="padding:15px">
    <div class="layui-form-item">
      <label class="layui-form-label">上传文件</label>
      <div class="layui-input-block">
        <input type="file" name="batchoperationfile" id="batchoperationfile" lay-type="file" />
        <div class="help-block" style="color:#F00"><a href="{$_W['siteroot']}addons/j_hmoney/template/resources/tempfile/memberupdate.xls" target="_blank">下载模板文件</a>,单次导入请不要多于1000条数据。</div>
      </div>
    </div>
    <div class="row">
    	<div class="col-md-12"><Div class="pull-right"> <button class="layui-btn" lay-submit="" lay-filter="btnupload">保存</button></Div></Div>
    </div>
  </form>
</div>

<div id="wxcardbox" style="display:none;">
  <form id="wxcardboxform" class="layui-form" action="" style="padding:15px">
  <input type="hidden" id="cardnum" value="0"/>
    <div class="progress">
      <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100"><span class="sr-only"></span></div>
    </div>
  </form>
</div>

<div id="batchOperation2" style="display:none;">
  <form id="batchOperation2form" class="layui-form" action="" style="padding:15px">
    <div style="padding:10px; height:400px; overflow-y:scroll">
      <table class="layui-table">
        <thead>
          <tr>			
            <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>							
            <th>卡号</th>
            <th>微信卡号</th>
            <th>等级</th>
            <th>余额</th>
            <th>积分</th>
            <th>姓名</th>
            <th>性别</th>
            <th>电话</th>
            <th>生日</th>
            <th>备注</th>
            <th>到期时间</th>
          </tr> 
        </thead>
        <tbody id="uploadmemberlist">
  
        </tbody>
      </table>
    </div>
    <div class="row">
    	<div class="col-md-12" style="margin-top:10px;"><button type="button" class="layui-btn layui-btn-danger" onclick="deleterow()" >删除</button> <button type="button" class="layui-btn" id="excelnum">0</button><Div class="pull-right"> <button class="layui-btn" lay-submit="" lay-filter="btnupload">导入</button></Div></Div>
    </div>
  </form>
</div>


<script language="javascript">
function deleteContent(url){
	layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
		location.href=url;
	});
}
var checkone=true;
$(document).ready(function(e) {

});
var memberLevel=eval("("+'{php echo json_encode($groupAry)}'+")");
layui.use(['layer', 'laypage', 'element','form'], function(){
	var layer = layui.layer
	,laypage = layui.laypage
	,element = layui.element
	,form = layui.form;
	form.render();
	laypage.render({
		elem: 'pageindex'
		,count: parseInt("{$total}")
		,limit: 10
		,curr: 1
		,jump: function(obj, first){
			var curr = obj.curr;
			if(first==true)return;
			var index2=layer.load(1, {shade: [0.1,'#fff']});
			$.post("{php echo $this->createWebUrl('member',array('op'=>'getmemberpage'))}",{"page":curr},function(returnstr){
				layer.close(index2);
				$("#memberlist").empty();
				var result=eval("("+returnstr+")");
				if(!result.success){
					layer.msg(result.msg,{icon:2,time:1000});
					return;
				}
				var list=result.list;
				var temp="";
				for(var i in list){
					temp+='<tr mid="'+list[i].id+'" onclick="checkthis(this)"><td><input type="checkbox" name="mid['+list[i].id+']" value="'+list[i].id+'" lay-skin="primary"></td><td>'+list[i].cardno+'</td><td>'+(parseInt(list[i].uid) ? '<span class="layui-badge-dot"></span>':"")+''+list[i].realname+'</td><td>'+list[i].mobile+'</td><td>'+memberLevel[list[i].gid]+'</td><td>'+list[i].credit+'</td><td>'+list[i].cash+'</td><td>';
					switch(parseInt(list[i].status)){
						case 0:
							temp+='<span class="label label-default">未启用</span>';
						break;
						case 1:
							temp+='<span class="label label-success">启用</span>';
						break;
						case 2:
							temp+='<span class="label label-danger">挂失</span>';
						break;
					}
					temp+='</td>';
					temp+='<td><a href="javascript:editBox('+list[i].id+')" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a><a href="javascript:deleteContent(\'{php echo $this->createWebUrl("member",array("op"=>"deletemember"))}&id='+list[i].id+'\')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a></td></tr>';
				}
				$("#memberlist").html(temp);
				form.render('checkbox');
			});
		}
	});
	
	
	form.on('submit(btnlost)', function(data){
		var num=0;
		var tempary=[];
		for(var i in data.field){
			tempary.push(data.field[i]);
			num++;
		}
		if(num==0){
			layer.msg("请选择要操作的对象",{icon:2,time:1500});
			return false;
		}
		layer.confirm('确认挂失？', function(){
			var index2=layer.load(1, {shade: [0.5,'#fff']});
			$.post("{php echo $this->createWebUrl('member',array('op'=>'deallost'))}",{"idary":tempary.join(",")},function(returnstr){
				layer.close(index2);
				var result=eval("("+returnstr+")");
				if(!result.success){
					layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
					return false;
				}
				layer.msg("处理成功",{icon:1,time:1000},function(){
					location.reload();
				});
			});
		});

		return false;
	});
	
	form.on('submit(btnsubmit)', function(data){
		var index2=layer.load(1, {shade: [0.5,'#fff']});
		$.post("{php echo $this->createWebUrl('member',array('op'=>'postmember'))}",data.field,function(returnstr){
			layer.close(index2);
			var result=eval("("+returnstr+")");
			if(result.success){
				layer.msg("处理成功",{icon:1,time:1500},function(){
					location.reload();
				});
			}else{
				layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
				return false;
			}
			
		});
		return false;
	});	
	
	//全选
	form.on('checkbox(allChoose)', function(data){
	  var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
	  child.each(function(index, item){
		item.checked = data.elem.checked;
	  });
	  form.render('checkbox');
	});
	
	form.on('submit(btnupload)', function(data){
		if(!$("#uploadmemberlist tr").size())return;
		var tempary=[];
		$("#uploadmemberlist tr").each(function(index, element) {
            tempary.push($(this).attr("rid"));
        });
		var index2=layer.load(1, {shade: [0.5,'#fff']});
		$.post("{php echo $this->createWebUrl('member',array('op'=>'insertexcel'))}",{rowid:tempary.join(",")},function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			var result=eval("("+returnstr+")");
			if(result.success){
				layer.msg("导入完成，共导入<b>"+result.num+"</b>条数据",{icon:1,time:1500},function(){
					location.reload();
				});
			}else{
				layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
				return false;
			}
		})
		
		return false;
	});	
	
	form.on('submit(btn_search)', function(data){
		var index2=layer.load(1, {shade: [0.1,'#fff']});
		$("input[name='datetime']").val(0);
		$.post("{php echo $this->createWebUrl('member',array('op'=>'getmember'))}",{"keyword":$("#txtTopupSeachStr").val()},function(returnstr){
			layer.close(index2);
			console.log();
			$("#txtTopupSeachStr").val("");
			var result=eval("("+returnstr+")");
			if(!result.success){
				layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
				return false;
			}
			var list=result.list;
			var temp="";
			for(var i in list){
				temp+='<tr mid="'+list[i].id+'" onclick="checkthis(this)"><td><input type="checkbox" name="mid['+list[i].id+']" value="'+list[i].id+'" lay-skin="primary"></td><td>'+list[i].cardno+'</td><td>'+(parseInt(list[i].uid) ? '<span class="layui-badge-dot"></span>':"")+''+list[i].realname+'</td><td>'+list[i].mobile+'</td><td>'+list[i].level+'</td><td>'+list[i].credit+'</td><td>'+list[i].cash+'</td><td>';
				switch(parseInt(list[i].status)){
					case 0:
						temp+='<span class="label label-default">未启用</span>';
					break;
					case 1:
						temp+='<span class="label label-success">启用</span>';
					break;
					case 2:
						temp+='<span class="label label-danger">挂失</span>';
					break;
				}
				temp+='</td>';
				temp+='<td><a href="javascript:editBox('+list[i].id+')" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a><a href="javascript:deleteContent(\'{php echo $this->createWebUrl("member",array("op"=>"deletemember"))}&id='+list[i].id+'\')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a></td></tr>';
			}
			$("#memberlist").html(temp);
			form.render('checkbox');
			return false;
		});
		return false;
	});	
});
function excelout(){
	window.open("{php echo $this->createWebUrl('member',array('op'=>'output'))}");
}
function checkthis(obj){
	$(obj).find("input[name^='mid']").click();
	var mid=$(obj).attr("mid");
	layui.use(['form'], function(){
		form = layui.form;
		form.render('checkbox');
	});
}
function batchOperation(){
	layer.open({
		type: 1,
		title:"批量导入会员",
		area:'400px',
		skin: 'layui-layer-rim',
		content:$("#batchOperation").show(),
		success: function(layero, index){
			$("#batchOperationform")[0].reset();
			layui.use('upload', function(){
				var upload = layui.upload;
				var uploadInst = upload.render({
					elem: '#batchoperationfile'
					,url: "{php echo $this->createWebUrl('member',array('op'=>'uploadfile'))}"
                    ,accept:"file"
                    ,exts:"xls"
					,done: function(returnstr){
						console.log(returnstr);
						var result=returnstr;
						if(result.success){
							layer.close(index);
							batchOperation2();
						}else{
							layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
							return;
						}
					}
					,error: function(){
						layer.alert("上传失败");
					}
				});
			});
		},
		end:function(){
			$("#batchOperation").hide();
		}
	});
}
function batchOperation2(){
	layer.open({
		type: 1,
		title:"批量导入会员",
		area:'900px',
		skin: 'layui-layer-rim',
		content:$("#batchOperation2").show(),
		success: function(layero, index){
			$("#uploadmemberlist").empty();
			var index2=layer.load(1, {shade: [0.5,'#fff']});
			$.post("{php echo $this->createWebUrl('member',array('op'=>'dealxls'))}",{},function(returnstr){
				console.log(returnstr);
				var result=eval("("+returnstr+")");
				if(result.success){
					var list=result.list;
					for(var i=0;i <list.length;i++){
						var temp='<tr rid="'+(i+1)+'"><td><input type="checkbox" name="rowid['+(i+1)+']" value="'+(i+1)+'" lay-skin="primary"></td><td>'+list[i][0]+'</td><td>'+list[i][1]+'</td><td>'+list[i][2]+'</td><td>'+list[i][3]+'</td><td>'+list[i][4]+'</td><td>'+list[i][5]+'</td><td>'+list[i][6]+'</td><td>'+list[i][7]+'</td><td>'+list[i][8]+'</td><td>'+list[i][9]+'</td><td>'+list[i][10]+'</td></tr>';
						$("#uploadmemberlist").append(temp);
					}
					$("#excelnum").text(list.length+"条");
					layui.use(['form'], function(){
						var form = layui.form;
						form.render('checkbox'); 
					});
					layer.close(index2);
				}else{
					layer.close(index2);
					layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
					return;
				}
			});
			
		},
		end:function(){
			$("#batchOperation2").hide();
		}
	});
}
function deleterow(){
	if(!$("#uploadmemberlist td .layui-form-checked").size())return;
	$("#uploadmemberlist td .layui-form-checked").parent().parent().remove();
}
function editBox(id){
	var til= id==0 ? "新增会员":"修改会员";
	$("#editform")[0].reset();
	layer.open({
		type: 1,
		title:til,
		area:'780px',
		skin: 'layui-layer-rim',
		content:$("#editbox").show(),
		success: function(layero, index){
			if(id){
				var index2=layer.load(1, {shade: [0.5,'#fff']});
				$.post("{php echo $this->createWebUrl('member',array('op'=>'getmember'))}",{"id":id},function(data){
					layer.close(index2);
                    console.log(data)
					if(id){
						var items=data.item;
						$("#editbox input[name='id']").val(id);
						$("#editbox select[name='gid']").val(items.gid);
						$("#editbox input[name='cardno']").val(items.cardno);
						$("#editbox input[name='realname']").val(items.realname);
						$("#editbox input[name='mobile']").val(items.mobile);
						$("#editbox input[name='birdday']").val(items.birdday);
						$("#editbox input[name='endtime']").val(items.endtime);
						$("#editbox input[name='wxcardno']").val(items.wxcardno);
						$("#editbox input[name='credit']").val(items.credit);
						$("#editbox input[name='cash']").val(items.cash);
						$("#editbox input[name='label']").val(items.label);
						$("#editbox input[name='remark']").val(items.remark);
						$("input[name='sex'][value="+items.sex+"]").attr("checked",true); 
						$("input[name='status'][value="+items.status+"]").attr("checked",true); 
						layui.use(['form'], function(){
							form = layui.form;
							form.render();
						});
					}
				},'json');
			}
		},
		end:function(){
			$("#editbox").hide();
		}
	});
}

layui.use('laydate', function(){
	var laydate = layui.laydate;
	var myDate = new Date(); 
	var datenow=myDate.toLocaleDateString();
	laydate.render({ 
		elem: '#LAY_demorange_s'
		,min: '1960-01-01'
		,max: datenow.replace("/","-")
	});
	laydate.render({ 
		elem: '#LAY_demorange_e'
		,min: '2017-01-01'
		,max: '2030-01-01'
	});
});
</script>
{elseif $operation == 'display_chargefee'}
<style>
.member_header{text-align:center; margin-bottom:15px}
.member_header img{ width:90px; height:90px; border-radius:100%}
#memberinfobox .layui-form-item{margin-bottom:0; font-size:15px;}
#memberinfobox .layui-form-item .layui-form-label{ padding:0;font-size:15px; font-weight:bold}
.reduceclass{ color:#0C3}
.addclass{ color:#F90}
#txt_total{ font-size:20px; font-weight:bold; color:#F90; line-height:40px}
</style>
<div class="panelbox">
  <div class="panelbox-body">
    <div class="row">
    	<div class="col-md-4" style="border-right:1px solid #DDD" id="memberinfobox">
        	<div class="member_header">
            	<img src="" onerror="this.src='./resource/images/nopic-small.jpg'"/>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">会员卡号:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_cardno"></span>
                      </div>
                    </div>
                </div>
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">微信卡号:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_wxcardno"></span>
                      </div>
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">等级:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_gid"></span>
                      </div>
                    </div>
                </div>
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">姓名:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_realname"></span>
                      </div>
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">电话:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_mobile"></span>
                      </div>
                    </div>
                </div>
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">生日:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_birdday"></span>
                      </div>
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">余额:</label>
                      <div class="layui-input-block">
                        <span style="color:#F60; font-weight: bolder" id="m_cash"></span>
                      </div>
                    </div>
                </div>
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">积分:</label>
                      <div class="layui-input-block">
                        <span style="color:#F60; font-weight: bolder" id="m_credit"></span>
                      </div>
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">累计消费:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_cost"></span>
                      </div>
                    </div>
                </div>
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">有效期至:</label>
                      <div class="layui-input-block">
                        <span class="" id="m_endtime"></span>
                      </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-8">
        <form action="{php echo $this->createWebUrl('member',array('op'=>'memberpay'))}" method="post" class="layui-form" id="listform" enctype="multipart/form-data">
        	<div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">操作类型:</label>
                      <div class="layui-input-block">
                          <input type="radio" lay-filter="usetype" name="usetype" value="0" title="充值" checked/>
                          <input type="radio" lay-filter="usetype" name="usetype" value="1" title="消费" />
                          <input type="radio" lay-filter="usetype" name="usetype" value="2" title="退还"/>
                          <i class="fa fa-question-sign tips" tips="消费：用于扣除不明确消息内容的款项；退还：当某个订单扣除多了金额时，采用退还的方式将金额退还到客户卡余额；"></i>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                	
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label"><span id="txt_til">充值</span>金额:</label>
                      <div class="layui-input-block">
                          <input type="text" name="cash" onchange="setFee(this)" lay-verify="required" autocomplete="off" class="layui-input">
                          <input type="hidden" name="id" lay-verify="required|number" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="col-md-6" id="is_chargefun">
                  {php $wxcard=json_decode($shop['chargelist'],true)}
                  {if count($wxcard)}
                  {loop $wxcard $index $row}
                  <a href="javascript:" onclick="selectCash(this)" fee="{$index}" gift="{$row}" class="layui-btn layui-btn-primary">充<b>{$index}</b>送<b>{$row}</b></a>
                  {php $i++}
                  {/loop}
                  {/if}
                </div>
            </div>
            <div class="row"  id="is_gift">
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">赠送金额:</label>
                      <div class="layui-input-block">
                          <input type="text" name="gift" readonly autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row" id="paytype">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">支付方式:</label>
                      <div class="layui-input-block">
                          <input type="radio" lay-filter="paytype" name="paytype" value="2" title="现金" checked/>
                          <input type="radio" lay-filter="paytype" name="paytype" value="3" title="银行卡"/>
                          <input type="radio" lay-filter="paytype" name="paytype" value="0" title="微信" />
                          <input type="radio" lay-filter="paytype" name="paytype" value="1" title="支付宝" />
                        </div>
                    </div>
                </div>
            </div>
            <div class="row" id="is_code" style="display:none">
                <div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">扫码:</label>
                      <div class="layui-input-block">
                          <input type="text" name="qrcode" autocomplete="off" placeholder="请扫描客户的支付码" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">备注:</label>
                      <div class="layui-input-block">
                          <textarea name="remark" rows="5" class="layui-input" placeholder="不多于50字" autocomplete="off"></textarea>
                        </div>
                    </div>
                </div>
                <div class="col-md-6">
                	
                </div>
            </div>
            <div class="row">
            	<div class="col-md-6">
                	<div class="layui-form-item">
                      <label class="layui-form-label">合计:</label>
                      <div class="layui-input-block">
                        <span id="txt_total">￥0.00</span>
                      </div>
                    </div>
                </div>
                <div class="col-md-6">
                </div>
            </div>
            <div class="row">
                <div class="col-md-6">
                <div class="layui-form-item">
                      <label class="layui-form-label"></label>
                      <div class="layui-input-block">
                        <input type="checkbox" name="print" value="1" title="打印小票" checked/>
                        <button type="submit" class="layui-btn layui-btn-radius layui-btn-danger" lay-submit="" lay-filter="btnpay">确认操作</button> 
                      </div>
                    </div>
                	
                </div>
            </div>
            
        </form>
        </div>
    </div>
  </div>
</div>


<div class="panelbox">
  <form action="" method="post" class="layui-form" id="listform2" enctype="multipart/form-data">
  <input type="hidden" name="datetime"/>
    <div class="panelbox-head"> 
      <A href="javascript:" onclick="reFresh(0)"><i class="fa fa-refresh"></i> 刷新</A> 
      <A href="javascript:" onclick="reFresh(1)"><i class="fa fa-list-alt"></i> 最近1天</A>   
      <A href="javascript:" onclick="reFresh(3)"><i class="fa fa-list-alt"></i> 最近3天</A>   
      <A href="javascript:" onclick="reFresh(7)"><i class="fa fa-list-alt"></i> 最近7天</A>   
    </div>
    <div class="panelbox-body" style="padding:0">
      <div class="layui-form">
        <table class="layui-table" lay-skin="line">
          <thead>
            <tr>
              <th>卡号</th>
              <th>操作类型</th>
              <th>支付类型</th>
              <th>变动前金额</th>
              <th>操作金额</th>
              <th>赠送金额</th>
              <th>变动后金额</th>
              <th>操作时间</th>
              <th>备注</th>
            </tr>
          </thead>
          <tbody id="chargelist">
          </tbody>
        </table>
      </div>
    </div>
    <div class="panelbox-body" style="text-align:right"><div id="pageindex"></div></div>
  </form>
</div>

<div id="editbox" style="display:none;">
  <div class="layui-form">
      <table class="layui-table" lay-skin="line">
        <thead>
          <tr>
            <th style="width:120px">卡号</th>
            <th>姓名</th>
            <th>电话</th>
            <th>金额</th>
            <th>积分</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
        </tbody>
      </table>
</div>

<script language="javascript">

$(document).ready(function(e) {
	$(".tips").on("mouseover",function(){
		var txt=$(this).attr("tips");
		layer.msg(txt,{time:20000});
	}).on("mouseout",function(){
		layer.closeAll();
	})
    
});
var waitforpassword;
var groupAry=eval('({php echo json_encode($groupAry)})');
layui.use(['layer', 'laypage', 'element','form'], function(){
	var layer = layui.layer
	,laypage = layui.laypage
	,element = layui.element
	,form = layui.form;
	form.render();
	form.on('radio(usetype)', function(data){
		switch(parseInt(data.value)){
			case 0:
				$("#txt_til").text("充值");
				$("#is_gift").show();
				$("#is_chargefun").show();
				$("#paytype").show();
				
			break;
			case 1:
				$("#txt_til").text("消费");
				$("#is_gift").hide();
				$("#is_code").hide();
				$("#paytype").hide();
			break;
			case 2:
				$("#txt_til").text("退还");
				$("#is_gift").hide();
				$("#is_code").hide();
				$("#paytype").hide();
			break;
		}
	});
	
	form.on('radio(paytype)', function(data){
		switch(parseInt(data.value)){
			case 0:
				$("#is_code").show();
			break;
			case 1:
				$("#is_code").show();
			break;
			case 2:
				$("#is_code").hide();
			break;
			case 3:
				$("#is_code").hide();
			break;
		}
	});
	
	form.on('submit(btnpay)', function(data){
		var index2=layer.load(1, {shade: [0.1,'#fff']});
		$("#pageindex").empty();
		$.post("{php echo $this->createWebUrl('member',array('op'=>'memberpay'))}",data.field,function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			var result=eval("("+returnstr+")");
			if(!result.success){
				layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
				return;
			}
			if(result.paywait){
				layer.alert('请稍等，需要用户支付密码<br>如果长时间没有支付，可取消支付', {
					skin: 'layui-layer-molv'
					,icon: 1
					,closeBtn: 0
					,title:0
					,btn:['取消订单']
				}, function(){
					layer.msg('请稍等，等待用户输入密码<br>如果长时间没有支付，可取消支付', {
						skin: 'layui-layer-molv'
						,icon:0
						,shade: 0.1
						,time:15000
					}, function(){
						  layer.alert('请稍等，需要用户支付密码<br>如果长时间没有支付，可取消支付', {
							  skin: 'layui-layer-molv'
							  ,icon: 0
							  ,closeBtn: 0
							  ,title:0
							  ,btn:['取消订单']
						  },function(){
							  layer.confirm('确认撤销此订单？', {
								  btn: ['确认','关闭']
							  }, function(){
								  $.post("{php echo $this->createWebUrl('member',array('op'=>'reversepay'))}",{"pid":result.pid},function(returnstr){
									   if(returnstr.success){
										   layer.closeAll();
										   clearTimeout(waitforpassword);
										   $("#listform")[0].reset();
										   $("#txt_total").text("￥0.00");
									   }else{
										   layer.msg(result.msg,{icon:2,time:2000});
									   }
								  },'json');
							  });
							   
						  });
					});
				});
				waitforpassword=setTimeout(function(){waitForPass(result.pid)},5000);
				return false;
			}
			layer.msg("操作成功",{icon:1,time:1000},function(){
				$("#listform")[0].reset();
				$("#txt_total").text("￥0.00");
				selectMember(data.field.id);
			});
			
		});
		return false;
	});
	form.on('submit(btn_search)', function(data){
		var index2=layer.load(1, {shade: [0.1,'#fff']});
		$("input[name='datetime']").val(0);
		$.post("{php echo $this->createWebUrl('member',array('op'=>'getmember'))}",{"keyword":data.field.txtTopupSeachStr},function(returnstr){
			layer.close(index2);
			console.log(returnstr);
			$("#txtTopupSeachStr").val("");
			var result=eval("("+returnstr+")");
			if(result.success){
				$("#chargelist").empty();
				var list=result.list;
				if(list.length>1){
					var temp='';
					for(var i in list){
						temp+='<tr><td>'+list[i].cardno+'</td><td>'+list[i].realname+'</td><td>'+list[i].mobile+'</td><td>'+list[i].cash+'</td><td>'+list[i].credit+'</td><td><a href="javascript:selectMember('+list[i].cardno+')" class="layui-btn layui-btn-normal layui-btn-small">选择</a></td></tr>';
					}
					$("#editbox tbody").html(temp);
					layer.open({
						type: 1,
						title:"选择会员",
						area:'700px',
						skin: 'layui-layer-rim',
						content:$("#editbox").show(),
						end:function(){
							$("#editbox").hide();
						}
					});
				}else if(list.length==1){
					selectMember(list[0].id);
				}
			}else{
				layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
				return false;
			}

			return false;
		});
		return false;
	});	
});
function waitForPass(pid){
	clearTimeout(waitforpassword);
	$.post("{php echo $this->createWebUrl('member',array('op'=>'waitforpass'))}",{"pid":pid},function(returnstr){
		var result=eval("("+returnstr+")");
		if(!result.success){
			layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
			return;
		}
		if(result.paywait){
			waitforpassword=setTimeout(function(){waitForPass(pid)},5000);
			return;
		}
		layer.msg("支付成功",{icon:1,time:1000},function(){
			$("#listform")[0].reset();
			$("#txt_total").text("￥0.00");
			selectMember(result.id);
		});
	});
}
function selectCash(obj){
	var fee=parseFloat($(obj).attr("fee"));
	var gift=parseFloat($(obj).attr("gift"));
	$("input[name='cash']").val(fee.toFixed(2));
	$("input[name='gift']").val(gift.toFixed(2));
	$("#txt_total").text("￥"+fee.toFixed(2));
}
function setFee(){
	var fee=parseFloat($("input[name='cash']").val());
	if(isNaN(fee))fee=0;
	if(fee==0){
		$("input[name='gift']").val("0.00");
		$("#txt_total").text("￥0.00");
		return;
	}
	$("#txt_total").text("￥"+fee.toFixed(2));
	var chargelist='{$shop["chargelist"]}';
	if(chargelist.length>5){
		var chargeAry=eval("("+chargelist+")");
		var giftfee=0;
		for(var i in chargeAry){
			if(fee<i)break;
			if(fee>=i)giftfee=chargeAry[i];
		}
		giftfee=parseFloat(giftfee);
		$("input[name='gift']").val(giftfee.toFixed(2));
	}
}
function selectMember(id){
	$("#listform")[0].reset();
	$("#txt_total").text("￥0.00");
	var datetime=$("input[name='datetime']").val();
	var index2=layer.load(1, {shade: [0.1,'#fff']});
	$("#pageindex").empty();
	$.post("{php echo $this->createWebUrl('member',array('op'=>'getmemberinfo'))}",{"id":id,"datetime":datetime},function(returnstr){
		layer.close(index2);
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(!result.success){
			layer.msg(result.msg ? result.msg : returnstr,{icon:2,time:2000});
			return;
		}
		var items=result.item;
		$("#m_cardno").text(items.cardno);
		$("#listform input[name='id']").val(items.id);
		var sex="";
		if(items.sex=="1"){
			sex="先生";
		}else if(items.sex=="2"){
			sex="女士";
		}
		$("#m_realname").text(items.realname+" "+sex);
		$("#m_wxcardno").text(items.wxcardno);
		$("#m_mobile").text(items.mobile);
		$("#m_gid").text(items.level);
		$("#m_birdday").text(items.birdday);
		$("#m_endtime").text(items.endtime);
		$("#m_cash").text(items.cash);
		$("#m_credit").text(items.credit);
		$("#m_cost").text(items.cost);
		formatList(result.list);
		layui.use(['laypage'], function(){
			var laypage = layui.laypage;
			
			laypage.render({
				elem: 'pageindex'
				,count: result.total
				,limit: 10
				,curr: 1
				,jump: function(obj, first){
					var curr = obj.curr;
					if(first==true)return;
					var index2=layer.load(1, {shade: [0.1,'#fff']});
					$.post("{php echo $this->createWebUrl('member',array('op'=>'getmembercharge'))}",{"page":curr,"id":id,"datetime":datetime},function(returnstr2){
						layer.close(index2);
						console.log(returnstr2);
						$("#memberlist").empty();
						var result2=eval("("+returnstr2+")");
						if(!result2.success){
							layer.msg(result2.msg,{icon:2,time:1000});
							return;
						}
						formatList(result2.list);
					});
				}
			});
		});
	});
}

function fee2num(num){
	if(num.indexOf(".")>-1)return num;
	var fee=(parseInt(num)*0.01).toFixed(2);
	return fee;
}
function fromatTime(time){
	var datetime = new Date();
	datetime.setTime(time*1000);
	var year = datetime.getFullYear();
	var month = datetime.getMonth() + 1;
	var date = datetime.getDate();
	var hour = datetime.getHours();
	var minute = datetime.getMinutes();
	var second = datetime.getSeconds();
	var mseconds = datetime.getMilliseconds();
	if(hour<10)hour="0"+hour;
	if(month<10)month="0"+month;
	if(minute<10)minute="0"+minute;
	
	var timetype="m/d h:i";
	if(arguments[1])timetype=arguments[1];
	timetype=timetype.replace("y",year);
	timetype=timetype.replace("m",month);
	timetype=timetype.replace("d",date);
	timetype=timetype.replace("h",hour);
	timetype=timetype.replace("i",minute);
	timetype=timetype.replace("s",second);
	return timetype;
}
function formatList(obj){
	var list=obj;
	var temp='';
	for(var i in list){
		temp+='<tr><td>'+$("#m_cardno").text()+'</td>';
		switch(parseInt(list[i].usetype)){
			case 0:
				temp+='<td><span class="label label-success">充值</span></td>';
			break;
			case 1:
				temp+='<td><span class="label label-warning">消费</span></td>';
			break;
			case 2:
				temp+='<td><span class="label label-danger">退还</span></td>';
			break;
		}
		switch(parseInt(list[i].paytype)){
			case 0:
				temp+='<td><span class="label label-success">微信</span></td>';
			break;
			case 1:
				temp+='<td><span class="label label-info">支付宝</span></td>';
			break;
			case 2:
				temp+='<td><span class="label label-warning">现金</span></td>';
			break;
			case 3:
				temp+='<td><span class="label label-primary">银行卡</span></td>';
			break;
			default:
				temp+='<td>-</td>';
			break;
		}
		temp+='<td>'+fee2num(list[i].startfee)+'</td>';
		temp+=parseInt(list[i].usetype)==1 ? '<td class="reduceclass">￥ '+fee2num(list[i].cash)+'</td>':'<td class="addclass">￥ +'+fee2num(list[i].cash)+'</td>';
		temp+='<td>'+fee2num(list[i].gift)+'</td><td>'+fee2num(list[i].endfee)+'</td><td>'+fromatTime(list[i].createtime)+'</td><td>'+list[i].remark+'</td></tr>';
	}
	$("#chargelist").html(temp);
}

function reFresh(num){
	var id=$("#listform input[name='id']").val();
	if(!id)return;
	$("input[name='datetime']").val(num);
	selectMember(id);
}
</script>

{elseif $operation == 'display_gift'}

<style>
.panelbox-head a{ margin-right:10px}
</style>
<div class="panelbox">
<form action="" method="post" class="layui-form" id="listform" enctype="multipart/form-data">
  <div class="panelbox-head"> 
  	<A href="#" onclick="editBox(0)"><i class="fa fa-plus"></i> 新增礼品</A> 
  </div>
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
            <th>编号</th>
            <th>名称</th>
            <th>类型</th>
            <th>内容</th>
            <th>所需积分</th>
            <th>数量</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody>
          {loop $list $row}
          <tr>
            <td>{$row['goodsn']}</td>
            <td>{$row['title']}</td>
            <td>{php echo $gifttype[$row['gtype']]}</td>
            <td>{$row['content']}</td>
            <td>{$row['credit']}</td>
            <td>{$row['num']} /{$row['remain']} / <b>{$row['store']}</b></td>
            <td class="text-right"><a href="javascript:giftbox({$row['id']})" class="layui-btn layui-btn-small"><i class="fa fa-gift"></i></a> <a href="javascript:editBox({$row['id']})" class="layui-btn layui-btn-normal layui-btn-small"><i class="layui-icon">&#xe642;</i></a> <a href="javascript:deleteContent('{php echo $this->createWebUrl('member',array('op'=>'deletegift','id'=>$row['id']))}')" class="layui-btn layui-btn-danger layui-btn-small"><i class="layui-icon">&#xe640;</i></a></td>
          </tr>
          {/loop}
        </tbody>
      </table>
    </div>
  </div>
  <div class="panelbox-foot">
  <div id="pageindex" class="pull-right"></div></div>
  </form>
</div>
<style>
</style>
<div id="editcatebox" style="display:none;">
  <form id="editcateform" class="layui-form layui-form-pane" action="" style="padding:15px">
    <input type="hidden" name="id" />
    <div class="layui-form-item">
      <label class="layui-form-label">名称</label>
      <div class="layui-input-block">
        <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="名称" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">编号</label>
      <div class="layui-input-block">
        <input type="text" name="goodsn" lay-verify="required" autocomplete="off" placeholder="编号" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">所需积分</label>
      <div class="layui-input-block">
        <input type="text" name="credit" lay-verify="required" autocomplete="off" placeholder="所需积分" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">单位</label>
      <div class="layui-input-block">
        <input type="text" name="unitname"  autocomplete="off" placeholder="单位" value="份" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">类型</label>
      <div class="layui-input-block">
        <select name="gtype"/>
          <option value="0" selected>实物</option>
          <option value="1">卡券</option>
          <option value="2">红包</option>
          <option value="3">余额</option>
        </select>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">内容</label>
      <div class="layui-input-block">
        <input type="text" name="content"  autocomplete="off" class="layui-input">
        <div class="help-block">实物不用填写；卡券，填写卡券id，随机卡券则用“|”分割；红包，填写金额元，随机金额1.00-2.00；余额，兑换金额；</div>
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">总数量</label>
      <div class="layui-input-block">
        <input type="text" name="store"  autocomplete="off" placeholder="总数量" value="-1" class="layui-input">
      </div>
    </div>
    <div class="layui-form-item">
      <label class="layui-form-label">剩余数量</label>
      <div class="layui-input-block">
        <input type="text" name="remain"  autocomplete="off" placeholder="剩余数量" value="-1" class="layui-input">
      </div>
    </div>
    <div class="row">
    	<div class="col-md-12"><Div class="pull-right"> <button class="layui-btn" lay-submit="" lay-filter="btnsubmit">保存</button></Div></Div>
    </div>
    
  </form>
</div>

<script language="javascript">
$(document).ready(function(e) {
    $('#btn_search').on('click',function(){
		var keyword=$("#txtTopupSeachStr").val();
		location.href="{php echo $this->createWebUrl('member',array('op'=>'display_gift'))}&keyword="+keyword;
	})
});
layui.use(['layer', 'laypage', 'element','form'], function(){
  var layer = layui.layer
  ,laypage = layui.laypage
  ,element = layui.element
  ,form = layui.form;
  form.render();
  form.on('submit(btnsubmit)', function(data){
	  $.post("{php echo $this->createWebUrl('member',array('op'=>'giftpost'))}",data.field,function(result){
		  if(!result.success){
			  layer.msg(result.msg,{icon:1,time:2000});
			  return;
		  }
		  location.reload();
	  },'json');
	  return false;
  });

  laypage.render({
	elem: 'pageindex'
	,count: parseInt("{$total}")
	,limit: 10
	,curr: parseInt("{php echo $pindex}")
    ,jump: function(obj, first){
	  var curr = obj.curr;
	  var keyword=$("#txtTopupSeachStr").val();
	  if(first==true)return;
	  location.href="{php echo $this->createWebUrl('member',array('op'=>'display_gift'))}&page"+curr+'&keyword='+keyword;
	}
  });
});


function deleteContent(url){
	layer.confirm('确认删除此内容？删除后将不可恢复', {}, function(){
		location.href=url;
	});
}

function editBox(id){
	var til= id==0 ? "新增":"修改";
	$("#editcateform")[0].reset();
	layer.open({
		type: 1,
		title:til,
		area:'700px',
		skin: 'layui-layer-rim',
		content:$("#editcatebox").show(),
		success: function(layero, index){
			if(id){
				var index2=layer.load(1, {shade: [0.5,'#fff']});
				$.post("{php echo $this->createWebUrl('member',array('op'=>'getgift'))}",{"id":id},function(data){
					layer.close(index2);
					if(id){
						var goods=data.item;
						$("#editcatebox input[name='id']").val(id);
						$("#editcatebox select").val(goods.gtype);
						$("#editcatebox input[name='goodsn']").val(goods.goodsn);
						$("#editcatebox input[name='title']").val(goods.title);
						$("#editcatebox input[name='credit']").val(goods.credit);
						
						$("#editcatebox input[name='content']").val(goods.content);
						$("#editcatebox input[name='store']").val(goods.store);
						$("#editcatebox input[name='remain']").val(goods.remain);
						
					}
				},'json');
			}
		},
		end:function(){
			$("#editcatebox").hide();
		}
	});
}

</script>
{elseif $operation == 'display_giftrecord'}
<div class="panelbox">
<form action="" method="post" class="layui-form" id="listform" enctype="multipart/form-data">
  <div class="panelbox-body">
    <div class="layui-form">
      <table class="layui-table">
        <thead>
          <tr>
            <th>卡号</th>
            <th>姓名</th>
            <th>礼品</th>
            <th>使用积分</th>
            <th>操作人</th>
            <th>日期</th>
            <th>操作</th>
          </tr>
        </thead>
        <tbody id="membergiftlist">
            
        </tbody>
      </table>
    </div>
  </div>
  <div class="panelbox-foot">
  <div id="giftlistpageindex" class="pull-right"></div></div>
  </form>
</div>
<script>
layui.use(['layer', 'laypage', 'element','form'], function(){
  var layer = layui.layer
  ,laypage = layui.laypage
  ,element = layui.element
  ,form = layui.form;
  

  funExtend_giftGetRecord(1);
});

function funExtend_giftGetRecord(pindex){
	var keyword=$("#mdl_id").val();
	var index2=layer.load(1, {shade: [0.1,'#fff']});
	$.post("{php echo $this->createMobileUrl('member',array('op'=>'getgiftrecord'))}",{keyword:keyword,page:pindex},function(returnstr){
		layer.close(index2);
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(!result.success){
			layer.msg(result.msg,{icon:2,time:1000});
			return;
		}
		if(pindex==1){
			layui.use(['laypage'], function(){
				var laypage = layui.laypage;
				
				laypage.render({
					elem: 'giftlistpageindex'
					,count: result.total
					,limit: 10
					,curr: 1
					,jump: function(obj, first){
						var curr = obj.curr;
						if(first==true)return;
						funExtend_giftGetRecord(curr);
						return;
					}
				});
			});
		}
		var list=result.list;
		var temp="";
		for(var i in list){
			temp+='<tr><td>'+list[i].cardno+'</td><td>'+list[i].realname+'</td><td>'+list[i].title+'</td><td>'+list[i].credit+'</td><td>'+list[i].username+'</td><td>'+fromatTime(list[i].createtime)+'</td>';
			if(parseInt(list[i].status)){
				temp+='<td><span class="label label-success">成功</span></td>';
			}else{
				temp+='<td><span class="label label-danger">失败</span> <button type="button" class="layui-btn layui-btn-small" onclick="funExtend_giftsend('+list[i].id+')">补发</button></td>';
			}
			temp+='</tr>';
		}
		$("#membergiftlist").html(temp);
	});
}
function funExtend_giftsend(id){
	var index2=layer.load(1, {shade: [0.1,'#fff']});
	$.post("{php echo $this->createMobileUrl('member',array('op'=>'sendgift'))}",{id:id},function(returnstr){
		layer.close(index2);
		console.log(returnstr);
		var result=eval("("+returnstr+")");
		if(!result.success){
			layer.msg(result.msg,{icon:2,time:1000});
			return;
		}else{
			layer.msg("操作成功",{icon:1,time:2000},function(){
				funExtend_getGift();
				funExtend_giftGetmember();
				funExtend_giftGetRecord(1);
			});
		}
	})
}
</script>
{/if}